package physics 
{
	import flash.geom.Point;
	import flash.utils.Timer;
	import GC;
	import Primitives.*;
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Tilemap;
	import net.flashpunk.masks.Grid;
	import players.Player;
	import net.flashpunk.World;
	
	/**
	 * ...
	 * @author Alex
	 */
	public class Physics extends Entity 
	{
		private var gravity:Number;
		private var time:Timer = new Timer(0,0);
		
		public function Physics():void
		{
			this.gravity = GV.WORLD_GRAVITY;
			layer = 3;
			type = GC.PHYSICS;
			trace("Gravity: " + gravity.toString());
			
		}
		
		override public function update():void 
		{		
			var a : Array = new Array();
			world.getLayer(1, a); //get all entities in a layer and apply the physics to them
			
			for (var i:int = 0; i < a.length-1; i++)
			{	
				//trace(i.toString()+":"+a[i]+":"+a[i].layer);
				if (a[i].layer == 1)
				{
					var p:Object = a[i];
					time.start();
					//a[i].y = a[i].y +this.gravity;
					p.y = p.y + (time.currentCount * ( time.currentCount * gravity));
					trace(time.currentCount);
					if (p.collide(GC.LEVEL, p.x, p.y)) //checks if entity hits the ground
						{
							p.y = Math.floor(p.y / 32) * 32;
							time.reset();
						}
				}
				
				
				
				
				//trace(i.toString()+":"+a[i]+":"+a[i].layer);	
			}
			//var p:Player = a[0];
			
			

		}
	}

}